package com.starblink.android.basic.widget.gloading

import android.view.View

class SkGLoadingAdapter : Gloading.Adapter {

    override fun getView(
        holder: Gloading.Holder,
        convertView: View?,
        status: Int,
        message: String?
    ): View {
        //convertView为可重用的布局
        //Holder中缓存了各状态下对应的View
        //	如果status对应的View为null，则convertView为上一个状态的View
        //	如果上一个状态的View也为null，则convertView为null
        var loadingView: SkLoadingGlobalStatusView? = null
        if (convertView != null && convertView is SkLoadingGlobalStatusView) {
            loadingView = convertView
        }
        if (loadingView == null) {
            loadingView = SkLoadingGlobalStatusView(holder.context, retryTask = holder.retryTask)
        }

        //show or not show msg view
        val data = holder.getData<Any>()

        loadingView.setStatus(status, message)

        return loadingView
    }
}